import { defineStore } from 'pinia'
import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    /** 用以收集用户选择的对象 */
    const consult = ref<PartialConsult>({})
    //设置问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    //设置极速问诊类型
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    //设置科室
    const setDep = (id: string) => (consult.value.depId = id)
    /** 设置病情描述 */
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    /** 设置患者id */
    const setPatientId = (id: string) => (consult.value.patientId = id)
    return { setPatientId, consult, setType, setIllnessType, setDep, setIllness }
  },
  {
    persist: true
  }
)
